package com.nhncorp.neptune.changelog;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;

public class ChangeLogDump {

  public static void main(String[] args) {
    File file = new File("./PipeBasedChangeLog.57011");
    
    //PrintStream out = System.out;
    PrintStream out = null;
	out = System.out;
		/*
    try {
      //out = new PrintStream(new FileOutputStream("D:\\temp\\dump.txt"));
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
      System.exit(-1);
    }
	*/
    
    if (file.exists()) {
      out.println("exist");
      try {
        FileInputStream in = new FileInputStream(file);
        DataInputStream dis = new DataInputStream(in);

        List<TransactionData> txDataList = ChangeLogClient.readTxDataFrom(dis);
        
        for(TransactionData data : txDataList) {
          out.println("ID : " + new String(data.id));
          out.println("Seq# : " + data.seq);
          out.println("log count : " + data.logList.length);
          
          for(int i = 0; i < data.logList.length; i++) {
            out.println("\n\tLOG# : " + i);

            out.println("\tOP : " + data.logList[i].getOperation());
            out.println("\tTableName : " + data.logList[i].getTableName());
            out.println("\tRowKey : " + data.logList[i].getRowKey());
            out.println("\tColumnName : " + data.logList[i].getColumnName());
            out.println("\tCellKey : " + data.logList[i].getCellKey());
          }
          
          out.println("\n");
        }
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      System.out.println("not exist");
    }
  }
}
